# RSS Feed Reader for display on LED Sign
# Created by Ian Fijolek
# Website: http://code.google.com/p/amplus-led-feed-reader/
# This is free software created under the GPL v3 License
# See http://www.gnu.org/licenses/gpl.html
# This header must stay intact
# Requires Toledo http://freezerpants.com/toledo/
# And Universal Feed Parser http://feedparser.org/

import subprocess
import feedparser
import time

global begin
global message
global end

begin = "python ./toledo.py --message=\""
message = "The Message"
end = "\" --font=0 --page=B -o"

i = 0
while 1 == 1:
	if i == 2:
		i = 0
		
	#Parse the data, returns a tuple: (data for channels, data for items)
	listFeeds = ["http://rss.slashdot.org/Slashdot/slashdot.xml", "http://www.macrumors.com/macrumors.xml"]
	theFeed = feedparser.parse(listFeeds[i])
	print "RSS Sign!  Press CTRL+C to Close"
	#print theFeed.feed.date
	#print "Parsed:" + theFeed.feed.date_parsed
	#print "Feed Title: " + theFeed.feed.title
	
	for item in theFeed.entries:
		print "Item Date: " + item.date
		print "Item Title: " + item.title
		print "Item Link: " + item.link
	
		message = item.title
		#child = subprocess.Popen("ls *.py", shell=True)
		child = subprocess.Popen(begin + message + end, shell=True)
		time.sleep(50)
		message = "From " + theFeed.feed.title
		child = subprocess.Popen(begin + message + end, shell=True)
		print " "
		print "RSS Sign!  Press CTRL+C to Close"
		time.sleep(10)
		
	i = i + 1
	
	#message = theFeed.entries[0].title

